import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/substation',
    alwaysShow: true,
    meta: { title: '概况', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/substation',
        name: 'Substation',
        component: () => import('@/views/substation/index'),
        meta: { title: '变配电站状态', icon: 'table' }
      }, {
        path: '/transformer',
        name: 'Transformer',
        component: () => import('@/views/transformer/index'),
        meta: { title: '变压器状态', icon: 'table' }
      }, {
        path: '/operationCenter',
        name: 'OperationCenter',
        component: () => import('@/views/operationCenter/index'),
        meta: { title: '运维中心', icon: 'table' }
      }, {
        path: '/energyMonthly',
        name: 'EnergyMonthly',
        component: () => import('@/views/energyMonthly/index'),
        meta: { title: '用能月报', icon: 'table' }
      }
    ]
  },
  {
    path: '/powerMonitoring',
    component: Layout,
    redirect: '/powerMonitoring',
    alwaysShow: true,
    meta: { title: '电力监测', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/eleOperationDaily',
        name: 'eleOperationDaily',
        component: () => import('@/views/eleOperationDaily/index'),
        meta: { title: '电力监测日报', icon: 'table' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
